package com.guli.mall.pms.controller;

import java.util.Arrays;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;

import com.guli.mall.pms.entity.SpuImagesEntity;
import com.guli.mall.pms.service.SpuImagesService;
import com.guli.common.utils.PageUtils;
import com.guli.common.utils.R;


/**
 * spu图片
 *
 * @author 罗俊华
 * @email 1007052116@qq.com
 * @date 2020-09-17 11:37:23
 */
@RestController
@RequestMapping("pms/spuimages")
public class SpuImagesController {
    @Autowired
    private SpuImagesService spuImagesService;


    @GetMapping("/list/{currentPage}/{size}")
    @ApiOperation("根据当前页和每页显示的记录数来获取spuImages分页列表")
    public R list(@PathVariable("currentPage") Integer currentPage, @PathVariable("size") Integer size) {
        PageUtils page = spuImagesService.queryPage(currentPage,size);

        return R.ok().put("page", page);
    }



    @GetMapping("/info/{id}")
    @ApiOperation("根据id获取SpuImages")
    public R info(@PathVariable("id") Long id) {
            SpuImagesEntity spuImages = spuImagesService.getById(id);

        return R.ok().put("spuImages", spuImages);
    }

    @PostMapping("/save")
    @ApiOperation("插入SpuImages")
    public R save(@RequestBody SpuImagesEntity spuImages) {
            spuImagesService.save(spuImages);

        return R.ok();
    }

    @PostMapping("/update")
    @ApiOperation("根据id更新SpuImages")
    public R update(@RequestBody SpuImagesEntity spuImages) {
            spuImagesService.updateById(spuImages);

        return R.ok();
    }

    @PutMapping("/deleteBatch")
    @ApiOperation("根据id批量删除SpuImages")
    public R delete(@RequestBody Long[] ids) {
            spuImagesService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
